package com.cloudsea.yunhaianalysis.controller;


import com.cloudsea.yunhaianalysis.dto.EventAddDTO;
import com.cloudsea.yunhaianalysis.entity.Events;
import com.cloudsea.yunhaianalysis.service.EventService;
import com.cloudsea.yunhaiutils.common.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Tag(name = "商家-事件管理", description = "商家用于记录未来经营活动或特殊事件的接口")
@RestController
@RequestMapping("/events")
public class EventController {

    @Autowired
    private EventService eventService;

    @Operation(summary = "新增事件记录")
    @PostMapping("/add")
    public ApiResponse<Events> addEvent(@Valid @RequestBody EventAddDTO dto) {
        Events newEvent = eventService.addEvent(dto);
        return ApiResponse.success("事件添加成功", newEvent);
    }

    @Operation(summary = "查询指定日期的事件")
    @GetMapping("/list")
    public ApiResponse<List<Events>> listEvents(@RequestParam Long storeId,
                                                @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        List<Events> events = eventService.listEventsByDate(storeId, date);
        return ApiResponse.success(events);
    }

    @Operation(summary = "删除事件记录")
    @DeleteMapping("/{eventId}")
    public ApiResponse<Void> deleteEvent(@PathVariable Long eventId) {
        eventService.deleteEvent(eventId);
        return ApiResponse.success("事件删除成功", null);
    }
}
